﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage2.master" AutoEventWireup="true" CodeFile="Admin_CapNhatSanPhamChiTiet.aspx.cs" Inherits="Admin_Admin_CapNhatSanPhamChiTiet" Title="Untitled Page" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script type="text/javascript" language="javascript">
function SoLuongHinhThucChange()
{   
    
    var text = document.getElementById("<%=txtSoLuongHinhThuc.ClientID %>").value;
    if(isNaN(text) == true)
    {
        alert('Phải nhập vào số lượng!');
        return false;
    }
    if(text == "")
    {
        document.getElementById("hinhthucPlaces").innerHTML="";
        return;
    }
    
    xmlhttp = GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Your browser does not support XML HTTP Request");
        return;
    }
    var serverURL="Admin_XuLyAjaxHienThiHinhThucKhuyenMai.aspx";
    serverURL=serverURL+"?q="+ text;
    serverURL=serverURL+"&sid="+Math.random();
    xmlhttp.onreadystatechange=HandleResponseFromServer;
    xmlhttp.open("GET",serverURL,true);
    xmlhttp.send(null);  

}
function checkOldValue(i)
{
    
    var hinhthuc = document.getElementsByName("oHinhThuc_"+i)[0].value;    
    var giatri = document.getElementsByName("oGiaTri_"+i)[0].value;
    
    if(isNaN(giatri) == true || giatri == "")
    {
        alert('Phải nhập vào số!');
        document.getElementById('goOn2').innerHTML="0";
        return false;
    }
    else
        document.getElementById('goOn2').innerHTML="1";
    if(hinhthuc == 2)
        return;
    xmlhttp = GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Your browser does not support XML HTTP Request");
        return false;
    }
    var serverURL="Admin_XuLyAjaxKiemTraSanPhamTonTai.aspx";
    serverURL=serverURL+"?q="+ giatri;
    serverURL=serverURL+"&sid="+Math.random();
    xmlhttp.onreadystatechange=HandleResponseFromServer3;
    xmlhttp.open("GET",serverURL,true);
    xmlhttp.send(null);  
   

}
</script>

</asp:Content>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <center><h2>Cập Nhật Sản Phẩm</h2></center>
    
    
    <div style="float:left"><asp:Image ID="imgHinhAnh" runat="server" Width="150" Height="150" />
    <asp:TreeView ID="tvPhanLoai" runat="server" 
                    ontreenodepopulate="tvPhanLoai_TreeNodePopulate" ExpandDepth="1" BorderStyle="Solid" BorderColor="Black" BorderWidth="1">
                    <SelectedNodeStyle BackColor="#D0D0D0" />
                </asp:TreeView>
    </div>
  
    
<table style="margin-left:200px;">    
   <tr>
   
   <td>Tên sản phẩm:</td>
   <td><asp:TextBox ID="txtTenSanPham" runat="server" MaxLength="200" Width="300"></asp:TextBox>
   </td>
   <td>
       <asp:RequiredFieldValidator ID="rqfvTenSanPham" runat="server" 
           ErrorMessage="RequiredFieldValidator" ControlToValidate="txtTenSanPham">*</asp:RequiredFieldValidator></td>
   </tr>
   
   <tr>
   <td>Số lượng:</td>
   <td><asp:TextBox ID="txtSoLuong" runat="server"></asp:TextBox>
   <asp:RequiredFieldValidator ID="rqfvSoLuong" runat="server" 
           ErrorMessage="RequiredFieldValidator" ControlToValidate="txtSoLuong">*</asp:RequiredFieldValidator></td>
   <td>
       <asp:RangeValidator ControlToValidate="txtSoLuong" ID="RangeValidator1" runat="server" ErrorMessage="Số lượng không đúng qui định" MaximumValue="99999" MinimumValue="0"></asp:RangeValidator>
      
                        </td>
   
   </tr>
   
   <tr>
   <td>Giá:</td>
   <td><asp:TextBox ID="txtGia" runat="server"></asp:TextBox>
   <asp:RequiredFieldValidator ID="rqfvGia" runat="server" 
           ErrorMessage="RequiredFieldValidator" ControlToValidate="txtGia">*</asp:RequiredFieldValidator></td>
   </td>
   <td>
       <asp:RangeValidator ID="RangeValidator2" runat="server" ErrorMessage="Giá không hợp lệ" ControlToValidate="txtGia" MaximumValue="999999999999" MinimumValue="0"></asp:RangeValidator>
                        </td>
   
       
   
   <tr>
   <td>Đơn vị tính:</td>   
   <td colspan="2">
       <asp:DropDownList ID="ddlDonViTinh" runat="server">
       </asp:DropDownList>
   </td>
   </tr>
   
   <tr>
   <td>Upload hình ảnh:</td>   
   <td><asp:FileUpload ID="fulHinhAnh" runat="server" /></td>
   </tr>
   
   <tr>
   <td>Nhà sản xuất:</td>
   <td><asp:TextBox ID="txtNhaSanXuat" runat="server" MaxLength="500" Width="250" 
           Rows="3"></asp:TextBox></td>
   <td>
       &nbsp;</td>
   </tr>
   
   <tr>
   <td>Mô tả:</td>
   <td><asp:TextBox ID="txtMoTa" runat="server" MaxLength="500" Rows="3" 
           TextMode="MultiLine" Width="247px"></asp:TextBox></td>
    <td>
        &nbsp;</td>
   </tr>  
   
   <tr>
   <td>Phân loại:</td>
   <td>    
       <asp:TextBox ID="txtMaPhanLoai" runat="server" ReadOnly="True"></asp:TextBox>
       </td>
   </tr>
   
   <% 
      
           string MaSP = Request.QueryString.Get("MaSP");
           DataDSTableAdapters.SANPHAMTableAdapter spadapter = new DataDSTableAdapters.SANPHAMTableAdapter();
           DataDS.SANPHAMDataTable sptable = spadapter.SANPHAM_LayTheoMaSP(MaSP);
           
           string strconnection = ConfigurationManager.ConnectionStrings["SMOConnectionString"].ConnectionString;
           System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(strconnection);
           connection.Open();
           string _value = sptable[0].Id_PhanLoai.ToString(); ;
           if (tvPhanLoai.SelectedValue != "" )
               _value = tvPhanLoai.SelectedValue;
           string query = "select tt.* " +
                          "from PHANLOAI_THUOCTINH pltt, THUOCTINH tt " +
                          "where pltt.Id_ThuocTinh=tt.Id and pltt.Id_PhanLoai=" + _value;
           System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
           command.CommandText = query;
           command.Connection = connection;
           System.Data.SqlClient.SqlDataReader dr= command.ExecuteReader();
           if (dr.RecordsAffected != 0)
           {
               DataDSTableAdapters.SANPHAM_THUOCTINHTableAdapter spttAdapter = new DataDSTableAdapters.SANPHAM_THUOCTINHTableAdapter();
               DataDS.SANPHAM_THUOCTINHDataTable spttTable = new DataDS.SANPHAM_THUOCTINHDataTable();
           
               while (dr.Read())
               {
                   string id = dr["Id"].ToString();
                   string ten = dr["TenThuocTinh"].ToString();
                   spttTable = spttAdapter.SANPHAM_THUOCTINH_LayThuocTinhBangMaSPvaIdThuocTinh(MaSP, int.Parse(id));
                   string giatri = "";
                   if (spttTable.Rows.Count > 0)
                       giatri = spttTable[0].GiaTri;
                   Response.Write("<tr>");
                   Response.Write("<td>" + ten + "</td>");
                   Response.Write("<td><input value='"+giatri+"' type='text' name='" + id +"'/></td>");
                   Response.Write("</tr>");
               }
               
           }
      
    %>
   
   <tr>   
    <td colspan="2" align="right">
       <asp:CheckBox ID="chkTrangThaiBan" runat="server" Text="Được Phép Bán" /></td>
   </tr>   
   
   <tr>
   <td colspan="4" align="center"><asp:Button ID="btnCapNhat" runat="server" 
           Text="Cập Nhật" onclick="btnCapNhat_Click" />
           <input type="button" value="Back" onclick="history.go(-1)" />
   </td>
           
   </tr>
   </table>
   <br />
   <br />
   <br />
   
   <div style="width:500px; margin-left:230px">
   <div class="itemHeader">
       <asp:Label ID="lbKhuyenMaiTitle" runat="server" Text=""></asp:Label></div>
       <asp:Panel ID="panelThemKhuyenMai" runat="server">
           <table border="0" cellspacing="10" cellpadding="0" width="100%">
           	    <tr>
                <td>
                    <asp:Label ID="lbNgayBatDau" runat="server" Text="Ngày bắt đầu"></asp:Label></td>
                <td>                    
                    <asp:TextBox ID="txtNgayBatDau" runat="server"></asp:TextBox>
                    <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtNgayBatDau">
                    </cc1:CalendarExtender>
                    
                </td>
           </tr>
           <tr>
                <td>
                    <asp:Label ID="lbNgayKetThuc" runat="server" Text="Ngày kết thúc"></asp:Label></td>
                <td>                    
                    <asp:TextBox ID="txtNgayKetThuc" runat="server"></asp:TextBox>
                    <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtNgayKetThuc">
                    </cc1:CalendarExtender>
                    
                </td>
           </tr>         
           <tr>
                <td>
                    <asp:Label ID="lbMoTa" runat="server" Text="Mô tả "></asp:Label></td>
                <td>
                    <asp:TextBox ID="txtMoTaKhuyenMai" runat="server" TextMode="MultiLine"></asp:TextBox></td>
           </tr> 
               <asp:Label ID="lbHinhThucCuPlaces" runat="server" Text=""></asp:Label>
           <tr>
                <td><asp:Label ID="lbSoLuongHinhThuc" runat="server" Text="Số lượng hình thức:"></asp:Label> </td>
                <td>                    
                    <asp:Panel ID="Panel1" runat="server">
                    <input type="text" runat="Server" size="5" id="txtSoLuongHinhThuc" name="soluonghinhthuc" onkeyup="SoLuongHinhThucChange();"/>
                    </asp:Panel>
                    
                    
                </td>
           </tr>
           </table>
           <span id="hinhthucPlaces">
               <asp:Label ID="lbHinhThucPlaces" runat="server" Text=""></asp:Label></span>
            <div style="padding-left:20px; width:420px; text-align:center"><asp:Button ID="btnThem" runat="server" onclick="btnThem_Click" Text="Cập nhật" 
                                Width="74px" />
            </div>
            <div id="goOn" style="display:none"></div>
            <div id="goOn2" style="display:none"></div> 
       
       
       </asp:Panel>
      
   </div>
   
   </asp:Content>

